﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:Helpers="clr-namespace:External.Controls.Helpers"
                    xmlns:Controls="clr-namespace:External.Controls.Controls"
                    xmlns:ModelViews="clr-namespace:External.Controls.ModelViews"
                    x:Class="External.Controls.Resources.Styles.c__users_vadimptr_desktop_cashier_solutioneditorcashier_cashier_resources_styles_designeritem_xaml">

    <Helpers:TestConverter x:Key="test"/>
    
    <Style TargetType="Path">
        <Setter Property="Fill" Value="SkyBlue"/>
        <Setter Property="Stroke" Value="Blue"/>
        <Setter Property="StrokeThickness" Value="1"/>
        <Setter Property="StrokeLineJoin" Value="Round"/>
        <Setter Property="Stretch" Value="Fill"/>
        <Setter Property="IsHitTestVisible" Value="False"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="BitmapEffect">
            <Setter.Value>
                <DropShadowBitmapEffect Color="#AAA" Direction="315" ShadowDepth="6"/>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:DragThumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:DragThumb}">
                    <Rectangle Fill="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="toSectionButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Rectangle Fill="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:DesignerItem}">
        <Setter Property="MinWidth" Value="10"/>
        <Setter Property="MinHeight" Value="10"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:DesignerItem}">
                    
                    <!-- Сюда приходит DesignerItem-->
                    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">

                        <Rectangle Name="PART_Selection" Stroke="Black" Margin="-3" StrokeThickness="1" Visibility="Collapsed" />
                        
                        <!-- Здесь отображается Path -->
                        <ContentPresenter x:Name="PART_ContentPresenter"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Content="{TemplateBinding ContentControl.Content}"
                                          Margin="{TemplateBinding ContentControl.Padding}" />

                        <!-- Возможно уберу нужно для кликабельности -->
                        <Rectangle Fill="Transparent" />

                        <!-- Для перетаскивания -->
                        <Controls:DragThumb x:Name="PART_DragThumb" 
                                     Visibility="Collapsed"
                                     Cursor="SizeAll"/>

                        <!-- Для отображение имени -->
                        <TextBlock Text="{Binding Path=DataContext.Section.Name}" 
                                   VerticalAlignment="Center" HorizontalAlignment="Center"
                                   FontSize="16"
                                   IsHitTestVisible="False"/>
                      
                        <!-- Кнопочка благодаря которой мы попадем в секцию-->
                        <Button Command="{Binding Path=NavigationCommand, RelativeSource={RelativeSource AncestorType={x:Type Controls:HallCanvas}}}" 
                                CommandParameter="{Binding Path=DataContext}"
                                Style="{StaticResource toSectionButtonStyle}"
                                Name="PART_toSectionButton"
                                Visibility="Visible"/>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:HallCanvas}},Path=IsEdit}">
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="PART_toSectionButton" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}"/>
                                <Condition Value="{x:Static System:Guid.Empty}" Binding="{Binding RelativeSource={RelativeSource Self},Path=ParentID}"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="PART_Selection" Property="Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ModelViews:BoolToBrushConverter x:Key="boolToBrush" />
    <ModelViews:BoolToThicknessConverter x:Key="boolToThickness" />
    <ModelViews:BoolToVisibilityConverter x:Key="boolToVisibility" />

    <DataTemplate x:Key="NotInSale">
        <Border Width="40" Height="40" 
                Name="outer"
                BorderThickness="1"
                BorderBrush="Gray"
                Background="White">
            <Border Name="inner" 
                    Background="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type Controls:SeatDesignerItem}}, Converter={StaticResource boolToBrush}}" 
                    BorderThickness="0.5">
                <Canvas>
                    <TextBlock Text="{Binding Path=Seat.Number}" FontSize="9" FontWeight="Bold"
                               Margin="1" Canvas.Left="3" Canvas.Top="3"/>
                </Canvas>
            </Border>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="Reserved">
        <Border Width="40" Height="40" 
                Name="outer"
                BorderThickness="1"
                BorderBrush="Gray"
                Background="White">
            <Border Name="inner" 
                    Background="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type Controls:SeatDesignerItem}}, Converter={StaticResource boolToBrush}}">
                <Canvas>
                    <Canvas>
                        <TextBlock Text="{Binding Path=Seat.Number}" FontSize="9" FontWeight="Bold"
                               Margin="1" Canvas.Left="3" Canvas.Top="3"/>
                    </Canvas>
                    <Line X1="38" Y1="0" X2="0" Y2="38" Stroke="Gray"/>
                </Canvas>
            </Border>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="Sold">
        <Border Width="40" Height="40" 
                Name="outer"
                BorderThickness="1"
                BorderBrush="Gray"
                Background="White">
            <Border Name="inner" 
                    Background="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type Controls:SeatDesignerItem}}, Converter={StaticResource boolToBrush}}">
                <Canvas>                    
                    <TextBlock Text="{Binding Path=Seat.Number}" FontSize="9" FontWeight="Bold"
                               Margin="1" Canvas.Left="3" Canvas.Top="3"/>
                    <Line X1="38" Y1="0" X2="0" Y2="38" Stroke="Gray"/>
                    <Line X1="0" Y1="0" X2="38" Y2="38" Stroke="Gray"/>
                </Canvas>
            </Border>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="Agent">
        <Border Width="40" Height="40" 
                Name="outer"
                BorderThickness="1"
                BorderBrush="Gray"
                Background="White">
            <Border Name="inner" 
                    Background="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type Controls:SeatDesignerItem}}, Converter={StaticResource boolToBrush}}" 
                    BorderThickness="0.5">
                <Canvas>                
                    <TextBlock Text="{Binding Path=Seat.Number}" FontSize="9" FontWeight="Bold"
                               Margin="1" Canvas.Left="3" Canvas.Top="3"/>
                    <Line X1="19" Y1="19" X2="38" Y2="19" Stroke="Gray"/>
                    <Line X1="19" Y1="19" X2="19" Y2="38" Stroke="Gray"/>
                </Canvas>
            </Border>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="Sale">
        <Border Width="40" Height="40" 
                Name="outer"
                BorderThickness="3"
                BorderBrush="Red"
                Background="Red">
            <Border Name="inner" 
                    Background="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type Controls:SeatDesignerItem}}, 
                                         Converter={StaticResource boolToBrush}, ConverterParameter={x:Static Brushes.Red}}"
                    BorderBrush="Red"
                    BorderThickness="0.5">
                <Canvas>
                    <TextBlock Text="{Binding Path=Seat.Number}" FontSize="9" FontWeight="Bold" Foreground="White"
                               Margin="1" Canvas.Left="3" Canvas.Top="3"/>
                </Canvas>
            </Border>
        </Border>
    </DataTemplate>
    
    <Controls:SeatStateTemplateSelector x:Key="templateSelector" 
                                 NotInSale = "{StaticResource NotInSale}"
                                 Reserved = "{StaticResource Reserved}"
                                 Sold = "{StaticResource Sold}"
                                 Agent = "{StaticResource Agent}"
                                 Sale = "{StaticResource Sale}" />
   
    <Style TargetType="{x:Type Controls:SeatDesignerItem}">
        <Setter Property="MinWidth" Value="10"/>
        <Setter Property="MinHeight" Value="10"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:SeatDesignerItem}">

                    <Grid>
                        <ContentPresenter x:Name="PART_ContentPresenter"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Content="{TemplateBinding ContentControl.Content}"
                                          Margin="{TemplateBinding ContentControl.Padding}"
                                          ContentTemplateSelector="{StaticResource templateSelector}"/>
             
                        <!-- Для перетаскивания -->
                        <Controls:DragThumb x:Name="PART_DragThumb"
                                     DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                     Visibility="Collapsed"
                                     Cursor="SizeAll"/>
                                                
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:HallCanvas}}, Path=IsEdit}">
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>